package org.mch.func.str.singlerep;

import java.awt.event.MouseEvent;

import org.mch.biz.ui.BizEvent;
import org.mch.biz.ui.BizPanel;
import org.mch.swingm.core.MFileChooser;

/**
 * 描述：文件操作；
 * 
 * @author MCHUN；
 * 
 */
public class ClientEvent extends BizEvent {
	private static final long serialVersionUID = -8590108060646853821L;

	MFileChooser fileChooser;

	public ClientEvent(BizPanel panel) {
		super(panel);
	}

	protected void buttonClicked(MouseEvent e) throws Exception {
		if (e.getSource() == getPanel().getBtn_execute()) {
			execute();
		}
	}

	public void execute() {

		String str_template = getPanel().getText_template().getText();
		String str_repitem = getPanel().getText_repitem().getText();
		if (tool().isNull(str_template) || tool().isNull(str_repitem)) {
			return;
		}

		String[] repitems = str_repitem.split("\n");

		StringBuilder sb = new StringBuilder();

		for (String repitem : repitems) {
			sb.append(str_template.replace("<{[*]}>", repitem));
			sb.append("\n");
		}

		getPanel().getText_outresult().setText(sb.toString());
	}

	public ClientPanel getPanel() {
		return (ClientPanel) super.getPanel();
	}
}